<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <!-- <script src="https://unpkg.com/vue@next"></script> -->
    <script src="./vue.js"></script>
    <style>
      .active {
        color: rgb(193, 111, 231);
      }
      .hi {
        background-color: rgb(58, 238, 208);
      }
    </style>
  </head>

  <body>
    <div id="app">
      <p class="active">hello</p>

      <!-- 对象 {类名:boolean} -->
      <p :class="{active:false}">hello</p>
      <p :class="{active:isActive}">hello</p>
      <p :class="{active:isActive,hi:isActive}">hello</p>
      <button v-on:click="isActive = !isActive; error = !error">
        click({{!isActive}})
      </button>

      <!-- 和普通类不冲突 -->
      <p :class="{active:isActive}" class="hi">helloWorld</p>

      <!-- obj -->
      <p :class="classObj">classObj</p>

      <!-- 计算属性 -->
      <p :class="classObjComputed">classObjComputed</p>

      <!-- 数组 -->
      <p :class="[activeClass,errorClass]">数组</p>

      <!-- 数组&对象 组合使用 -->
      <p :class="[{active:isActive},errorClass]">数组&对象 组合使用</p>
    </div>

    <script>
      const App = {
        data: function () {
          return {
            hello: "HelloWorld",
            isActive: true,
            classObj: {
              active: true,
              hi: true,
            },
            error: false,
            activeClass: "active",
            errorClass: "hi",
          };
        },
        computed: {
          classObjComputed() {
            return {
              active: this.isActive && !this.error,
              hi: this.error,
            };
          },
        },
      };
      let app = Vue.createApp(App).mount("#app");
      console.log(app);
    </script>
  </body>
</html>
